﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLT_BLL;
using QLT_Public;

namespace GiaoDien
{
    public partial class frm_Thuoc_LoaiThuoc : DevExpress.XtraEditors.XtraForm
    {
        public frm_Thuoc_LoaiThuoc()
        {
            InitializeComponent();
        }
        LoaiThuoc_BLL loaithuoc_bll = new LoaiThuoc_BLL();
        public void LoadForm(int load)
        {
            txt_Load.Text = load.ToString();
        }
        private void frm_Thuoc_LoaiThuoc_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = loaithuoc_bll.LayDuLieu();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            frm_Thuoc_LoaiThuoc_Them f = new frm_Thuoc_LoaiThuoc_Them();
            f.Flag = 0;
            f.MyLoad = new frm_Thuoc_LoaiThuoc_Them.GetInt(LoadForm);
            f.ShowDialog();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            frm_Thuoc_LoaiThuoc_Them f = new frm_Thuoc_LoaiThuoc_Them();
            f.Flag =1;
            f.MyLoad = new frm_Thuoc_LoaiThuoc_Them.GetInt(LoadForm);
            f.MaLoaiThuoc=Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Mã Loại Thuốc"));
            f.TenLoaiThuoc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Loại Thuốc").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            LoaiThuoc_Public lt = new LoaiThuoc_Public();
            lt.MaLoaiThuoc = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Loại Thuốc"));
            lt.TenLoaiThuoc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Loại Thuốc").ToString();
            if (XtraMessageBox.Show("Bạn có muốn xóa Loại thuốc: '" + lt.TenLoaiThuoc + "' có Mã là: '" + lt.MaLoaiThuoc + "' này không?","Thông Báo",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
            {
                loaithuoc_bll.delete_LoaiThuoc(lt);
                frm_Thuoc_LoaiThuoc_Load(sender,e);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public delegate void GetInt(int loadform);
        public GetInt MyLoadMaLoai;
        private void btnChon_Click(object sender, EventArgs e)
        {

            MyLoadMaLoai(Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Mã Loại Thuốc")));
            this.Close();
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                frm_Thuoc_LoaiThuoc_Load(sender,e);
                txt_Load.Text = "0";
            }
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            MyLoadMaLoai(Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Loại Thuốc")));
            this.Close();
        }
    }
}